package cn.icatw.gulimall.product.web;

import cn.icatw.gulimall.product.service.SkuInfoService;
import cn.icatw.gulimall.product.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.ExecutionException;

/**
 * 项控制器
 *
 * @author icatw
 * @date 2022/3/20
 * @email 762188827@qq.com
 * @apiNote
 */
@Controller
public class ItemController {
    /**
     * sku信息服务
     */
    @Autowired
    SkuInfoService skuInfoService;

    /**
     * 展示当前sku项详情
     *
     * @param skuId sku id
     * @return {@link String}
     */
    @GetMapping("/{skuId}.html")
    public String skuItem(@PathVariable Long skuId, Model model) throws ExecutionException, InterruptedException {
        System.out.println("准备查询" + skuId + "的详情");
        SkuItemVo vo = skuInfoService.item(skuId);
        model.addAttribute("item", vo);
        return "item";
    }
}
